package com.csesteel.crm.service.impl;

import com.csesteel.crm.dao.CrmRoleDao;
import com.csesteel.crm.domain.CrmRole;
import com.csesteel.crm.service.CrmRoleService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2015/5/20 0020.
 */
@Service
public class CrmRoleServiceImpl implements CrmRoleService {

    private Log logger = LogFactory.getLog(CrmRoleServiceImpl.class);

    @Autowired
    private CrmRoleDao crmRoleDao;


    @Transactional
    public CrmRole getCrmRole(Integer id) {
        return crmRoleDao.get(CrmRole.class,id);
    }

    @Transactional
    public void saveCrmRole(CrmRole crmRole) {
        crmRoleDao.save(crmRole);
    }

    @Transactional
    public void deleteCrmRole(Integer id) {
        crmRoleDao.delete(CrmRole.class, id);
    }
    @Transactional
    public void updateCrmRole(CrmRole crmRole) {
        crmRoleDao.update(crmRole);
    }
    @Transactional
    public List<CrmRole> findAllCrmRole() {
        List<CrmRole> crmRoleList =  crmRoleDao.findAll(CrmRole.class);
        return crmRoleList;
    }

    @Transactional
    public Map findAllRoleByUserId(Integer id) {
        Map map =crmRoleDao.getCrmRoleByUserId(id);
        return map;
    }

    @Transactional
    public List<CrmRole> findAllCrmRoleByPage(int pageNo, int pageSize, String name) {
        return crmRoleDao.findAllCrmRoleByPage(pageNo,pageSize,name);
    }

    @Transactional
    public long findCount(String name) {
        return crmRoleDao.findCountRoleWithParams(name);
    }

    @Transactional
    public CrmRole getCrmRoleByCode(String roleCode) {
        return crmRoleDao.getCrmRoleByCode(roleCode);
    }

    @Transactional
    public void savePriviledgeByRole(Integer priviledgeId, Integer roleId) {
        crmRoleDao.savePriviledgeByRole(priviledgeId,roleId);
    }

    @Transactional
    public void deletePriviledgeByRole(Integer roleId) {
        crmRoleDao.deletePriviledgeByRole(roleId);
    }
}
